package com.k8.rpc;

import com.k8.common.Destructible;
import com.k8.common.annotation.SPI;
import com.k8.common.extension.Adaptive;
import com.k8.rpc.expoter.Exporter;
import com.k8.rpc.invoke.Invoker;
import com.k8.rpc.url.URL;

import java.util.Collections;
import java.util.List;

import static com.k8.common.constants.CommonKeyConstants.EXPORTER_KEY;

@SPI
// todo
public interface Protocol extends Destructible {
    @Adaptive(value = {EXPORTER_KEY})
    <T> Exporter<T> export(Invoker<T> invoker, URL url) throws RpcException;


    @Adaptive(value = {EXPORTER_KEY})
    <T> Invoker<T> refer(URL url, Class<T> serviceType) throws RpcException;

    /**
     * Destroy protocol: <br>
     * 1. Cancel all services this protocol exports and refers <br>
     * 2. Release all occupied resources, for example: connection, port, etc. <br>
     * 3. Protocol can continue to export and refer new service even after it's destroyed.
     */


    /**
     * Get all servers serving this protocol
     *
     * @return
     */
    default List<ProtocolServer> getServers() {

        return Collections.EMPTY_LIST;
    }
}
